<template>
  <div class="col_form office_first">
    <div class="input_wrapper">
      <div class="flex name">
        <label class="flex align-center justify-center"><span class="required-icon">*</span>主标题</label>
        <el-input
          placeholder="请输入主标题"
          v-model="formData.main_title"
          clearable
        >
        </el-input>
      </div>
    </div>
    <goods-add
      :maxNum="goodsNum"
      :goods-list="formData.goods"
      @setGoods="setGoods"
    ></goods-add>
  </div>
</template>

<script>
import goodsAdd from "./goodsAdd";
export default {
  components: { goodsAdd },
  props: ['goodsNum', 'levelName'],
  data() {
    return {
      formData: {
        main_title: '',
        goods: []
      }
    }
  },
  methods: {
    setGoods(list) {
      this.formData.goods = list;
    },
    save() {
      if (!this.formData.main_title) {
        this.$message({
          message: "主标题不能为空",
          type: "error"
        });
        return false;
      }
      let goodsidStr = '';
      if (this.formData.goods.length > 0) {
        goodsidStr += this.formData.goods.map(k => k.goods_id).join(',');
      }
      return {
        level: this.levelName,
        main_title: this.formData.main_title,
        goodsidStr
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.office_first {
  .input_wrapper {
    margin-top: 10px;
    margin-left: 0;
    & > div {
      label {
        width: 90px;
      }
    }
  }
}
</style>
